import { createApp } from "vue";
import "./style.css";
import App from "./App.vue";
import router from "./router/index";
import i18nPlugin from "./plugins/i18n";
import { createPinia } from "pinia";
import useLazy from "./core/hook/useLazy"
// -- 头部加载进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import MiLongUI from "./plugins/MiLongUI"; // --自定义ui库
import 'virtual:uno.css';
import Util from "./utils/util";
console.log(import.meta.env.VITE_APP_TITLE);
console.log(import.meta.env.VITE_API_ENDPOINT);
const app = createApp(App);
app.use(i18nPlugin, {
  greetings: {
    hello: "你好吗!",
  },
});
// --头部进度条
NProgress.configure({     
  easing: 'ease',  // 动画方式    
  speed: 500,  // 递增进度条的速度    
  showSpinner: false, // 是否显示加载ico    
  trickleSpeed: 200, // 自动递增间隔    
  minimum: 0.3 // 初始化时的最小百分比
})
// 自定义指令vue3
app.directive("focus", {
  mounted(el) {
    console.log(el)
    el.focus();
    el.addEventListener('blur', function () {
      // 失去焦点时，移除事件监听
      console.log('失去焦点了');
    })
  },
});


// 首屏加载时间
document.addEventListener('DOMContentLoaded', () => {
  // 获取 PerformanceNavigationTiming 数据
  if (performance.getEntriesByType) {
    const navigationEntries = performance.getEntriesByType('navigation');
    
    if (navigationEntries.length > 0) {
      const navEntry = navigationEntries[0];
      console.log(navEntry);
    }
  }

  // 获取 FCP
  if (performance.getEntriesByName) {
    const fcpEntry = performance.getEntriesByName('first-contentful-paint')[0];
    
    if (fcpEntry) {
      console.log('FCP 时间:', fcpEntry.startTime, 'ms');
    }
  }

  // 获取 LCP
  const lcpObserver = new PerformanceObserver((list) => {
    const lcpEntry = list.getEntries().find(entry => entry.entryType === 'largest-contentful-paint');
    
    if (lcpEntry) {
      console.log('LCP 时间:', lcpEntry.startTime, 'ms');
    }
    
    lcpObserver.disconnect();
  });

  lcpObserver.observe({ entryTypes: ['largest-contentful-paint'] });
});
console.log(window.devicePixelRatio);

 app.use(useLazy);
app.use(router);
app.use(createPinia());
app.use(MiLongUI);
app.config.globalProperties.$utils = Util;
app.mount("#app");
